﻿<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="vtc" uri="/vtc-core-tags"%>
<%@ include file="/common/taglibs.jsp"%>
<html>
<head>
	<title>Category Maintenance</title>
</head>
<body>

<script type="text/javascript">
	$(document).ready(function() {
		$("#categoryForm").validate();
	});

	function turnToCategoryCratePage() {
		$("#categoryForm").attr('action', 'category!createCategory.action');
		$("#categoryForm").submit();
	}
	function clickBtn(action) {
		switch (action) {
		case "search":
			
			$("#mainForm_search").attr("value", "true");
			$("#mainForm").attr("action", "category!list.action?canSelectMasterTree="+document.getElementById("canSelectMasterTree").value);
			break;
		case "clear":
			$("#mainForm_search").attr("value", "false");
			$("#mainForm").attr("action", "category!list.action?canSelectMasterTree="+document.getElementById("canSelectMasterTree").value);
			break;
		case "create":
			$("#planYear").attr("value", "");
			$("#planningExerciseName").attr("value", "");
			$("#mainForm").attr("action", "category!input.action");
			break;
		}
		$("#mainForm").submit();
	}
	function deleteCategory(categoryId){
		if(confirm('Confirm to delete ?')){
			$("#mainForm").attr('action', 'category!delete.action?deleteFromPage=list&categoryId='+categoryId);
			$("#mainForm").submit();
		}
	}
	
	function getLevelStatus(categoryId,index,isBranchTree){
		$.ajax({
			url : "category!getLevelStatus.action?categoryId="+ categoryId,
			cache : true,
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.FirstLevel!=null && data.FirstLevel!="" && data.FirstLevel!="undefined"){
					document.getElementById("level1Status_"+index).innerHTML=data.FirstLevel;
					if(!isBranchTree){
						document.getElementById("level2Status_"+index).innerHTML=data.SecondLevel;
						document.getElementById("level3Status_"+index).innerHTML=data.ThirdLevel;
					}
				}
			},
			error : function(data) {
				//alert(data);
			}
		});
	}
</script>

<div class="content">
	<div class="pageTitle">Planning Exercise Maintenance</div>
	<div class="form1">
		  <s:actionerror id="actionerror"/>
	  <s:fielderror/>
	  <s:actionmessage/> 
		<form id="mainForm" method="post">
			<s:hidden id="mainForm_search" name="search"></s:hidden>
			<table border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td class="sep"><img src="../images/spacer.gif"
						style="width: 150px;" />
					</td>
					<td class="sep"><img src="../images/spacer.gif"
						style="width: 150px;" />
					</td>
					<td class="sep sep2"><img src="../images/spacer.gif" />
					</td>
				</tr>
				<tr>
					<td><label class="fLabel">Planning Exercise</label>
						<div class="fField">
							<s:select id="planYear" name="category.planYear"
								list="categoryService.allCategoryOrderByYear" listKey="key" listValue="value"
								
								cssClass="inputSelect" cssStyle="width: 155px" headerValue="--All--" headerKey="">
							</s:select>
						</div>
					</td>
					<td><label class="fLabel">Planning Exercise Name</label>
						<div class="fField">
							<s:textfield id="planningExerciseName" name="category.planningExerciseName" cssClass="inputText"
								cssStyle="width: 300px"></s:textfield>
						</div>
					</td>
					<td><label class="fLabel" >Branch Name</label>
                         <div class="fField">
                           <s:textfield class="inputText" id="branchName" name="category.branchName" cssStyle="width:200px"/>
                         </div>
                    </td>
				</tr>
			</table>
			<div class="btnSet btnSetTypeB">
				<div class="left">
					<div class="button">
						<div class="left">
							<div class="right">
								<input class="inputButton" type="button" id="searchBtn"
									name="search" value="Search" onclick="clickBtn('search')" />
							</div>
						</div>
					</div>
					<div class="button">
						<div class="left">
							<div class="right">
								<input class="inputButton" type="button" id="" name=""
									value="Clear" onclick="clickBtn('clear')" />
							</div>
						</div>
					</div>
					<div class="button">
						<div class="left">
							<div class="right">
							<input type="hidden" id="canSelectMasterTree" value="false"/>
							<security:authorize access="hasRole('PLANNING_EXERCISE_INSERT')">
							<script>
							document.getElementById("canSelectMasterTree").value="true";
							</script>
								<input class="inputButton" type="button" id="" name=""
									value="Create Planning Exercise" onclick="clickBtn('create')" />
									</security:authorize>
							</div>
						</div>
					</div>
				</div>
			</div>
	</div>
	<s:if test="%{page!=null&&page.result!=null&&page.result.size()!=0}">
		<div class="sListBorder">
			<div class="sList">
				<table width="100%" cellspacing="0" cellpadding="0" border="0"
					class="sTable">
					<tbody>
						<tr>
							<td class="sTh t" style="width: 80px">Planning Exercise</td>
							<td class="sTh t">Planning Exercise Name</td>
							<td class="sTh t">Branch Name</td>
							<td class="sTh t">1st Level Status</td>
							<td class="sTh t">2nd Level Status</td>
							<td class="sTh t">3rd Level Status</td>
							<td class="sTh t">Endorsement Status</td>
							<td class="sTh t">Date of Endorsement</td>
							<td class="sTh t">Action</td>
						</tr>
						<s:iterator value="page.result" var="category" status="status" >
							<s:set var="trClass" value="'sRow1'"></s:set>
					    	  <s:if test="#status.index%2==0">
					       	 		<s:set var="trClass" value="'sRow2'"></s:set>
						       	 <s:else>
						       	    <s:set var="trClass" value="'sRow1'"></s:set>
						       	 </s:else>
							  </s:if>
							<tr  class="<s:property value='#trClass'/>">
								<td class="sCell" id="yearTD_<s:property value='#status.index' />"><s:property value="#category.planYear" /></td>
								<script>
								var year = "<s:property value='#category.planYear' />";
								var toYear = parseInt(year) + 1;
								document.getElementById("yearTD_<s:property value='#status.index' />").innerHTML=year+"/"+toYear.toString().substring(2,4);
								</script>
								<s:if test="%{#category.branchName!=null && #category.branchName!=''}">
									<td class="sCell"><s:property value="#category.planningExerciseName" /></td>
									<td class="sCell"><a
											href="category!input.action?categoryId=<s:property value='#category.id'/>"><s:property
													value="#category.branchName" /> </a></td>
									
									
									<td class="sCell" id="level1Status_<s:property value='#status.index' />"></td>
									<td class="sCell" id="level2Status_<s:property value='#status.index' />">-</td>
									<td class="sCell" id="level3Status_<s:property value='#status.index' />">-</td>
									<script>
										getLevelStatus("<s:property value='#category.id'/>","<s:property value='#status.index' />",true);
									</script>
									<td class="sCell"><s:property value="#category.endorsementStatus.label" /></td>
									<td class="sCell">-</td>
									
									
								</s:if>
								<s:else>
									<td class="sCell"><a
										href="category!input.action?categoryId=<s:property value='#category.id'/>"><s:property
												value="#category.planningExerciseName" /> </a></td>
									<td class="sCell">-</td>
									
									
									<td class="sCell" id="level1Status_<s:property value='#status.index' />"></td>
									<td class="sCell" id="level2Status_<s:property value='#status.index' />"></td>
									<td class="sCell" id="level3Status_<s:property value='#status.index' />"></td>
									<script>
										
										getLevelStatus("<s:property value='#category.id'/>","<s:property value='#status.index' />",false);
									</script>
									<td class="sCell">&nbsp;<s:property value="#category.endorsementStatus.label" /></td>
									<td class="sCell">&nbsp;<s:property value="#category.endorsementTime" /></td>
								</s:else>
								
								<td class="sCell">
									<div class="button sbtn" >
                                      <div class="left" >
                                        <div class="right" >
                                        <security:authorize access="hasRole('PLANNING_EXERCISE_DELETE')">
                                          <input class="inputButton" type="button" id="" name="" value="Delete" onclick="deleteCategory('<s:property value='#category.id'/>')"/>
                                        </security:authorize>
                                        </div>
                                      </div>
                                    </div>
								</td>
							</tr>
						</s:iterator>
					</tbody>
				</table>
			</div>
			<vtc:paging page="%{page}"></vtc:paging>
		</div>
	</s:if>
	</form>
	<!-- InstanceBeginEditable name="content" -->




	<!-- InstanceEndEditable -->
</div>

</body>
</html>
